//
const ssr = require('./ssr/svg/namespace/SVGNamespace');

cc.Class({
    extends: cc.Component,

    properties: {
        svgNode: cc.Node,
        logView: cc.ScrollView,
    },

    onLoad () {
        cc.debug.setDisplayStats(true);
        this._testcase = cc.director.getScene().name;
        cc.Canvas.instance.node.getChildByName("Title").getComponent(cc.Label).string = "Testcase - " + this._testcase;
    },

    start () {
        this._strokeAnimateSpeed = 0.1 * 0.1;
        //
        this._writerComponent = this.svgNode.getComponent(ssr.SVG.WriterComponent);
        this._writerComponent.drawFrame();
        this._writerComponent.drawGrid();
        this._writerComponent.drawMedians();
        this._writerComponent.drawHanzi();
    },

    onEditingReturn (event) {
        let hanzi = event.textLabel.string;
        let self = this;
        this._writerComponent.load(hanzi, function (err) {
            self._writerComponent.resetHanziRender()
            if (!err) {
                self._writerComponent.drawHanzi();
            }
        });
    },

    onGrid (event) {
        this._writerComponent.showGrid = event.isChecked;
    },

    onGridWidth (event) {
        this._writerComponent.gridWidth = (10 * event.progress);
    },

    onGridLength (event) {
        this._writerComponent.gridLength = (10 * event.progress);
    },

    onGridColor (event) {
        this._writerComponent.gridColor = cc.color(255 * Math.random(), 255 * Math.random(), 255 * Math.random(), 255);
    },

    onFrame (event) {
        this._writerComponent.showFrame = event.isChecked;
    },

    onFrameColor (event) {
        this._writerComponent.frameColor = cc.color(255 * Math.random(), 255 * Math.random(), 255 * Math.random(), 255);
    },

    onFrameFillColor (event) {
        this._writerComponent.frameFillColor = cc.color(255 * Math.random(), 255 * Math.random(), 255 * Math.random(), 255 * Math.random());
    },

    onFrameWidth (event) {
        this._writerComponent.frameWidth = (10 * event.progress);
    },

    onFramePadding (event) {
        this._writerComponent.framePadding = (20 * event.progress);
    },

    onHanziFillColor (event) {
        this._writerComponent.hanziFillColor = cc.color(255 * Math.random(), 255 * Math.random(), 255 * Math.random(), 255);
    },

    onHanziOutlineColor (event) {
        this._writerComponent.hanziOutlineColor = cc.color(255 * Math.random(), 255 * Math.random(), 255 * Math.random(), 255 * Math.random());
    },

    onHanziOutlineWidth (event) {
        this._writerComponent.hanziOutlineWidth = (10 * event.progress);
    },

    onFlipX (event) {
        this._writerComponent.flipX = event.isChecked;
    },

    onFlipY (event) {
        this._writerComponent.flipY = event.isChecked;
    },

    onMedians (event) {
        this._writerComponent.showMedians = event.isChecked;
    },

    onMediansColor (event) {
        this._writerComponent.mediansColor = cc.color(255 * Math.random(), 255 * Math.random(), 255 * Math.random(), 255);
    },

    onMediansWidth (event) {
        this._writerComponent.mediansWidth = (10 * event.progress);
    },

    onMediansControlPoint (event) {
        this._writerComponent.showMediansControlPoint = event.isChecked;
    },

    onMediansControlPointColor (event) {
        this._writerComponent.mediansControlPointColor = cc.color(255 * Math.random(), 255 * Math.random(), 255 * Math.random(), 255);
    },

    onMediansControlPointSize (event) {
        this._writerComponent.mediansControlPointSize = (10 * event.progress);
    },

    onBack () {
        cc.director.loadScene('TestList');
    }

});
